﻿/*
This project and all of its code is/are Copyright (C) 2017  Nils Hunter Alving

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;

namespace DynamicTypeBuilder.ConstrainedType.Examples
{
    /// <summary>
    /// A constrained list of pred-defined repeat interval values.
    /// This is a somewhat contrived example that demonstrates how to use the ConstrainedTypeBase class to create
    /// an enum-like class that accepts spaces and special characters in the name
    /// </summary>
    public class RepeatInterval : ConstrainedTypeBase<string>
    {
        /// <summary>
        /// Declare all acceptable values as constants
        /// </summary>
        public const string Daily = "Daily";
        /// <summary>
        /// Declare all acceptable values as constants
        /// </summary>
        public const string EveryOtherDay = "Every other day";
        /// <summary>
        /// Declare all acceptable values as constants
        /// </summary>
        public const string Weekly = "Weekly";
        /// <summary>
        /// Declare all acceptable values as constants
        /// </summary>
        public const string OnceAWeek = "Once a week";
        /// <summary>
        /// Declare all acceptable values as constants
        /// </summary>
        public const string BiWeekly = "Bi-weekly";

        /// <summary>
        /// Consolidate all acceptable values into a single list
        /// </summary>
        private static List<string> DefinedValues = new List<string>()
        {
            Daily,
            EveryOtherDay,
            Weekly,
            BiWeekly
        };

        /// <summary>
        /// The default constructor
        /// </summary>
        public RepeatInterval() : base(DefinedValues)
        {
        }

        /// <summary>
        /// An implicit operator used to allow direct conversion of a string to the ConstrainedType
        /// </summary>
        /// <param name="interval">A string that is one of the defined values</param>
        public static implicit operator RepeatInterval(string interval)
        {
            return new RepeatInterval()
            {
                Value = interval
            };
        }
    }
}
